<!DOCTYPE html>
<html lang="zh-cn" class="no-js">
	<head>
		<meta http-equiv="Content-Type">
		<meta content="text/html; charset=utf-8">
		<meta charset="utf-8">
		<title>立即购买</title>		
		<meta name="viewport" content="target-densitydpi=device-dpi, width=750px, user-scalable=no">
		<meta name="format-detection" content="telephone=no">
		<meta name="format-detection" content="email=no">
		<script src="/zghpt/js/jquery-3.1.0.min.js"></script>
		<script type="text/javascript">
		function adaptscreen(widthnum){
			try{
			 var DEFAULT_WIDTH = widthnum, // 页面的默认宽度
		        ua = navigator.userAgent.toLowerCase(), // 根据 user agent 的信息获取浏览器信息
		        deviceWidth = window.screen.width, // 设备的宽度
		        devicePixelRatio = window.devicePixelRatio || 1, // 物理像素和设备独立像素的比例，默认为1
		        targetDensitydpi;    // Android4.0以下手机不支持viewport的width，需要设置target-densitydpi
		        if (ua.indexOf("android") !== -1 && parseFloat(ua.slice(ua.indexOf("android")+8)) < 4) {
		        	targetDensitydpi = DEFAULT_WIDTH / deviceWidth * devicePixelRatio * 160;
		        	$('meta[name="viewport"]').attr('content', 'target-densitydpi=' + targetDensitydpi + ', width=device-width, user-scalable=no');
				}else{
					$('meta[name="viewport"]').attr('content', 'target-densitydpi=device-dpi, width='+DEFAULT_WIDTH+'px, user-scalable=no');
				}
			}catch(e){
				console.log('dpi error',e);
			}
	    }
	    adaptscreen(750);
		</script>
		<style type="text/css">
			*{
				margin: 0px;
				padding: 0px;
				
			}

			html,body{
				overflow:hidden;
			}

			img{
				vertical-align:middle;
			}

			#mask{
				display: none;
				position: absolute;
				z-index: 900;
				width: 100%;
				height: 100%;
				left: 0;
				top:0;
				background: rgba(0, 0, 0, 0.5);
			}

			#buy {
				position: fixed;
				bottom: 100px;
				text-align: center;
				width: 100%;
			}
		</style>
		<link rel="stylesheet" type="text/css" href="/zghpt/css/reset.css?v=6" />
        <link rel="stylesheet" type="text/css" href="/zghpt/css/load.css?v=6" /> 
	</head>
	<body>

		<div id="loading" style="display:none;">
			<div class="spinner">
				<div class="double-bounce1"></div>
				<div class="double-bounce2"></div>
			</div>
		</div>

		<div id="mask"></div>

		<!-- form start -->
		<form id="myForm" action="/third/wechat/auth-receipt" method="post" style="display:none;">
			<input type="hidden" name="_token" value="{{ csrf_token() }}" />
			<input type="hidden" name="user" id="hiddenUser" />
			<input type="hidden" name="url" id="hiddenURL" />
			<input type="submit" value="Submit" />
		</form>
		<!-- form end -->

		<a href="javascript:pay();">
			<img src="/images/zghpt_vip_bg_v2.jpg" />
			<div id="buy">
				<img src="/images/zghpt_vip_btn_v2.png?1" />
			</div>
		</a>

		<script type="text/javascript">

            document.addEventListener('touchmove', function (e) {
                if (e.target.nodeName == '#document') {
                    e.preventDefault();
                } else {
                    e.stopPropagation();
                }
            })

        // 发起支付
        function pay() {
            $("#loading").show();
            $("#mask").show();

            $.ajax({
                type: "get",
                url: "/api/third/wechat/prepare",
                data: {
                    product: 1
                },
                success: function(jdata){
                    $("#loading").hide();
                    $("#mask").hide();

                    if (jdata.code == 1000) {

                        // 发起微信支付
                        wxPay( $.parseJSON(jdata.results) );

                    } else if (jdata.code == 9000) {

                        alert('系统繁忙，请稍后再试');

                    } else if (jdata.code == 9001) {

						// 发起权限绑定
						$('#hiddenUser').val(jdata.results.user);
						$('#hiddenURL').val(location.href);
						$('#myForm').submit();

                    } else if (jdata.code == 9002) {

                        alert(jdata.msg);

                    }
                },
                error: function(){
                }
            });
        }

        // 发起微信支付
        function wxPay(jsStr) {
            $("#loading").show();
            $("#mask").show();

            console.log(jsStr);
            WeixinJSBridge.invoke(
                'getBrandWCPayRequest', jsStr,
                function(res){
                    $("#loading").hide();
                    $("#mask").hide();

        //            alert(res.err_msg);
                    if(res.err_msg == "get_brand_wcpay_request:ok" ) {
                        //成功
                        // console.log('成功');
						alert('购买成功');

                    } else {
                        alert('购买失败，请重新发起！');
                    }
                }
            );
        }

		</script>
	</body>
</html>		